/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : SynonymAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Jan 5, 2009       Raghu Sarraff			       Created
 */
package lwf.web.struts.action.word;

import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.factory.SynonymFactory;
import lwf.handler.IProcessHandler;
import lwf.handler.english.word.SynonymHandler;
import lwf.web.struts.action.BaseAction;

import net.lwf.util.web.WebUtil;
import net.lwf.web.constant.IPageTitle;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


/**
 * Type the class description here
 *  
 */
//public class SynonymAction extends DispatchAction {
public class SynonymAction extends BaseAction {

	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		WebUtil.removeAttribute(request, "picklist");
		return mapping.findForward("home");
	} //home
	
	public ActionForward pick(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
        String alphabet = (String) request.getParameter("alphabet");
        //List data = (List) PropertyReader.getInstance().getSynonyms().get(alphabet);
        Map data = (Map) SynonymFactory.getInstance().getSynonyms().get(alphabet);
        WebUtil.setAttribute(request, "picklist", data);
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println(SynonymHandler.getPickList(data));
		out.flush();

		return null; // Not forwarding to anywhere, response is fully-cooked
	} //pick
	
	public ActionForward display(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
        String synonymkey = (String) request.getParameter("synonymkey");
        Map data = (Map) WebUtil.getAttribute(request, "picklist");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println(SynonymHandler.displaySynonyms(synonymkey, data));
		out.flush();

		return null; // Not forwarding to anywhere, response is fully-cooked
	} //pick

	@Override
	public IProcessHandler getHandler(HttpServletRequest request) {
		return null;
	}
	
	@Override
	public String getPageTitle() {
		return IPageTitle.SYNONYMS;
	}

	@Override
	public String getMainTitle() {
		return null;
	}

	@Override
	public String getPdfLink() {
		return null;
	}

	@Override
	public String getQuizLink() {
		return null;
	}
	
}

